package com.tanhua.app.controller;

import com.tanhua.app.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessageController {

  	@Autowired
    private MessageService messageService;

    @PostMapping(value = "/contacts",name = "加为好友")
    public ResponseEntity contactUser(@RequestBody Map<String, Object> param) {
        Long friendId = Long.valueOf(param.get("userId").toString());
        return this.messageService.contactUser(friendId);
    }
    @GetMapping(value = "/contacts",name = "当前登录人的好友")
    public ResponseEntity contactsList(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")  Integer pagesize,
                                       String keyword) throws InvocationTargetException, IllegalAccessException {
        return messageService.contactsList(page,pagesize);
    }

    @GetMapping(value = "/likes",name="点赞的用户列表")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize) throws IOException {

        return messageService.findPage(page,pagesize,1);

    }

    @GetMapping(value = "/comments",name="评论的用户列表")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize) throws IOException {

        return messageService.findPage(page,pagesize,2);
    }

    @GetMapping(value = "/loves",name="喜欢的用户列表")
    public ResponseEntity loves(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize) throws IOException {

        return messageService.findPage(page,pagesize,3);
    }

}
